package com.cyj.dream.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @Description: 路由限流
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.gateway.config
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-27 12:49
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Configuration(proxyBeanMethods = false)
public class RateLimiterConfiguration {

    @Bean(value = "remoteAddrKeyResolver")
    public KeyResolver remoteAddrKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
    }

}

